package com.atguigu.exer.meiju2;

/*
public enum TrafficLight {
    RED,YELLOW,GREEN;
    public TrafficLight nextState(){
        TrafficLight t = switch (this){
            case RED -> YELLOW;
            case YELLOW -> GREEN;
            case GREEN -> RED;
        };
        return t;
    }
}
*/

//枚举类中如果定义了抽象方法，那么每一个枚举对象都要单独实现这个抽象方法
public enum TrafficLight {
    RED{
        @Override
        public TrafficLight nextState() {
            return YELLOW;
        }
    },
    YELLOW{
        @Override
        public TrafficLight nextState() {
            return GREEN;
        }
    },GREEN{
        @Override
        public TrafficLight nextState() {
            return RED;
        }
    };

    public abstract TrafficLight nextState();
}
